/**
 * 写入cookie
 * exhours: 过期时间（单位：小时）
*/
export function setCookie(key,value, exhours){
    let exp = new Date()
    exp.setTime(exp.getTime() + exhours * 60 * 60 * 1000)
    document.cookie = key + "="+ escape (value) + ";expires=" + exp.toGMTString()
}

// 读取cookie
export function getCookie(name){
    let reg = new RegExp("(^| )"+name+"=([^;]*)(;|$)"),
        arr = document.cookie.match(reg)
    if(arr) {
      return unescape(arr[2])
    } else {
      return null
    }
}

// 删除cookies
export function delCookie(name) {
    let exp = new Date(),
        cval = getCookie(name)
    exp.setTime(exp.getTime() - 1)
    if(cval) {
      document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
}